<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>
<body>
    <script>
        // // 为什么要用console.log
        // var obj = {};
        // document.write(obj);
        // console.log(obj);

        // typeof ------------------------
        var iNum = 1;
        console.log('typeof(iNum) = ' + typeof(iNum)); // number
        console.log('typeof iNum = ' + typeof iNum);
        var str = 'abc';
        console.log('typeof(str) = ' + typeof(str)); // string
        console.log('typeof str = ' + typeof str);
        var booleanValue = true;
        console.log('typeof(booleanValue) = ' + typeof(booleanValue));
        console.log('typeof booleanValue = ' + typeof booleanValue);
        var obj = null;
        console.log('typeof(obj) = ' + typeof(obj));
        console.log('typeof obj = ' + typeof obj);
        var undefinedValue = undefined;
        console.log('typeof(undefinedValue) = ' + typeof(undefinedValue));
        console.log('typeof undefinedValue = ' + typeof undefinedValue);
        var noAssignmentValue;
        console.log('typeof(noAssignmentValue) = ' + typeof(noAssignmentValue));
        console.log('typeof noAssignmentValue = ' + typeof noAssignmentValue);

        // 显示类型转换----------------------
        // Number();
        iNum = Number(false);
        console.log('Number(false) = ' + iNum);
        iNum = Number(true);
        console.log('Number(true) = ' + iNum);
        iNum = Number(undefined);
        console.log('Number(undefined) = ' + iNum);
        iNum = Number(null);
        console.log('Number(null) = ' + iNum);
        iNum = Number('10');
        console.log('Number(10) = ' + iNum);
        iNum = Number('1.5');
        console.log('Number(1.5) = ' + iNum);
        iNum = Number('1.5.3');
        console.log('Number(1.5.3) = ' + iNum);
        iNum = Number('');
        console.log("Number('') = " + iNum);
        // undefined => NaN; 不是数，=> NaN

        // parseInt() // parse, parser
        iNum = parseInt('1234');
        console.log("parseInt('1234') = " + iNum);
        iNum = parseInt('100px');
        console.log("parseInt('100px') = " + iNum);
        iNum = parseInt('a1234');
        console.log("parseInt('a1234') = " + iNum); // NaN

        // 0x---- 16进制数 C/C++; ---h 16进制数 汇编语言
        var iNum = parseInt('0xA0');
        console.log("parseInt('0xA0') = " + iNum); // 160
        // 0---- 8进制，C/C++ 以0开头表示8进制，无效
        iNum = parseInt('070');
        console.log("parseInt('070') = " + iNum); // 70 无效
        iNum = parseInt('');
        console.log("parseInt('') = " + iNum);
        iNum = parseInt('1.1E5');
        console.log("parseInt('1.1E5') = " + iNum);
        iNum = parseInt('123.9');
        console.log("parseInt('123.9') = " + iNum);
        iNum = parseInt('A0', 16);
        console.log("parseInt('A0', 16) = " + iNum);
        iNum = parseInt('70', 8);
        console.log("parseInt('70', 16) = " + iNum);
        iNum = parseInt(undefined);
        console.log('parseInt(undefined) = ' + iNum);
        iNum = parseInt(null);
        console.log('parseInt(null) = ' + iNum);
        iNum = parseInt(false);
        console.log('parseInt(false) = ' + iNum);
        // 如何记忆Number()和parseInt()的区别
        // Number本质上可以转化为数字，parseInt是看上去像数字的。
        // 1. Number可以，parseInt不可以：false, null, ''
        // 2. Number不可以，parseInt可以：数字开头掺杂其它。
        // 3. 都不可以：undefined，字母开头的字符串

        // parseFloat();
        var fNum = parseFloat('10');
        console.log("parseFloat('10') = " + fNum);
        fNum = parseFloat('10.00');
        console.log("parseFloat('10.00') = " + fNum);
        fNum = parseFloat('10.5');
        console.log("parseFloat('10.5') = " + fNum);
        fNum = parseFloat('10.5');
        console.log('[parseFloat] = ' + fNum);
        
        fNum = parseFloat('1.5.3');
        console.log('[parseFloat] = ' + fNum);
        
        fNum = parseFloat(' 1.7 ');
        console.log('[parseFloat] = ' + fNum);
        
        fNum = parseFloat('1.5aaa');
        console.log('[parseFloat] = ' + fNum);
        
        fNum = parseFloat('1.1E5');
        console.log('[parseFloat] = ' + fNum);

        // isNaN() 调用Number()
        console.log('[isNaN] = ' + isNaN(NaN)); // true
        console.log('[isNaN] = ' + isNaN('aaa')); // true
        console.log('[isNaN] = ' + isNaN(undefined)); // true
        console.log('[isNaN] = ' + isNaN(null)); // false
        console.log('[isNaN] = ' + isNaN('1234')); // false
        console.log('[isNaN] = ' + isNaN('')); // false

    </script>
</body>
</html>